function timeFormat(timeStamp, formatStr) {
  timeStamp = Number(timeStamp);
  var time = new Date(timeStamp);
  var formatStred = formatStr;
  var timeObj = {
    "Y+": time.getFullYear(),
    "M+": time.getMonth() + 1,
    "d+": time.getDate(),
    "h+": time.getHours(),
    "m+": time.getMinutes(),
    "s+": time.getSeconds(),
  };

  for (const key in timeObj) {
    var rge = new RegExp(key);
    let isContain = rge.test(formatStr);

    if (!isContain) return;
    //YYYY格式完 更新一下formatstr 不然永远是初始值 replace不改变原数组
    formatStred = formatStred.replace(rge, (timeObj[key] + "").padStart(2, "0")); //padStart 补齐 对字符串使用
    // console.log(formatStr.replace(rge, timeObj[key]));
  }
  return formatStred;
}

exports.timeFormat = timeFormat;
